package com.ss.project.xia17user.rest;

import com.ss.project.xia17user.core.exceptions.BadRequestException;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.web.reactive.error.DefaultErrorAttributes;
import org.springframework.http.HttpStatus;
import org.springframework.security.web.savedrequest.RequestCache;
import org.springframework.security.web.savedrequest.SavedRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 测试controller
 * @author xia17
 * @since 2020/9/14 18:03
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("test")
public class TestRest {


    @GetMapping("test")
    public  void test(HttpServletRequest request, HttpServletResponse response) throws IOException {
        request.setAttribute("org.springframework.boot.web.servlet.error.DefaultErrorAttributes.ERROR",new BadRequestException("测试错误信息"));
        System.out.println(response.getClass().getName());
        response.sendError(HttpStatus.BAD_REQUEST.value());
    }


    @GetMapping("exception")
    public  void exception() throws IOException {
        throw new BadRequestException("你是我的世界");
    }


    @GetMapping("testA")
    public  void testA(HttpServletRequest request) throws IOException {
        throw new BadRequestException("你是我的世界");
    }




}
